/**********************************
 * @Author: Ronnie Zhang
 * @LastEditor: Ronnie Zhang
 * @LastEditTime: 2023/12/05 21:25:59
 * @Email: zclzone@outlook.com
 * Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
 **********************************/

import { defineStore } from 'pinia'

export const useGlobalTask = defineStore('globalTask', {
  state: () => ({
    timedSwitch: false,
    timedIds: [],
  }),
  actions: {
    pushTimed(id) {
      this.timedSwitch = true
      for (let i = 0; i < this.timedIds.length; i++) {
        if (this.timedIds[i] === id) {
          continue
        }
        clearTimeout(this.timedIds[i])
      }
      this.timedIds.push(id)
    },
    clearAllTimed() {
      for (let i = 0; i < this.timedIds.length; i++) {
        clearTimeout(this.timedIds[i])
      }
      this.timedSwitch = false
    },
  },
  getters: {
    getTimed() {
      if (this.timedIds.length === 0) {
        return false
      }
      else {
        return this.false[0]
      }
    },
    getTimedSwitch() {
      return this.timedSwitch
    },
  },
})
